package com.example.demo.controller;

import com.example.demo.entity.Bill;
import com.example.demo.entity.User;
import com.example.demo.mapper.BillMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class MyController {


    //    @Autowired
//    BillMapper billMapper;
    ///@PostMapping("/")
    @ResponseBody
    @GetMapping("/findBiilsByWhere")  //请求地址
    public List<Bill> findBiilsByWhere(Bill bill) {

        bill = new Bill();
        //商品名称商品名称
        // bill.setGoodsName("手机");
        //bill.setSupplier("华为");

        //  List<Bill> bills = billMapper.findBiilsByWhere(bill);
        // System.out.println(bills);
        return null;
    }


    @GetMapping("/toPasswordPage")  //请求地址
    public String toPasswordPage() {
        return "page/password";
    }



      //RestController
    @GetMapping("/checkPassword")
    @ResponseBody
     public String checkPassword(HttpServletRequest request, String password)
    {
        String msg="";
        User user = (User)request.getSession().getAttribute("user");
        if(!user.getPassword().equals(password))
        {
            msg="密码输入错误";
        }
        return msg;
    }

    @GetMapping("/toUserAddPage")  //请求地址
    public String toUserAddPage(Bill bill) {

        return "page/userAdd";
    }


    @GetMapping("/checkUsername")  //请求地址
    @ResponseBody
    public String checkUsername(String username) {

        System.out.println(username);
        return "aaaaa";


    }


}
